package cn.stylefeng.guns.modular.system.warpper;

import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.modular.system.model.OrderMer;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.page.PageResult;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;
import java.util.Map;

public class OrderWrapper extends BaseControllerWrapper {
    public OrderWrapper(Map<String, Object> single) {
        super(single);
    }

    public OrderWrapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    public OrderWrapper(Page<Map<String, Object>> page) {
        super(page);
    }

    public OrderWrapper(PageResult<Map<String, Object>> pageResult) {
        super(pageResult);
    }

    @Override
    protected void wrapTheMap(Map<String, Object> map) {
        String orderid = map.get("id").toString();
        if(ToolUtil.isNotEmpty(map.get("state"))){
            String orderstate = map.get("state").toString();
            map.put("state", ConstantFactory.me().getDictName(Integer.parseInt(orderstate)));
        }
        List<Map<String,Object>> orderMerList = ConstantFactory.me().getOrderMerList(orderid);
        for(Map map1 : orderMerList){
            String attr = map1.get("merattr").toString();
            if(ToolUtil.isNotEmpty(attr)){
                Map<String, Object> attrToJson = JSON.parseObject(attr);
                attrToJson.forEach((key, value) -> {
                            attrToJson.put(key, ConstantFactory.me().getDictName(Integer.parseInt(value.toString())));
                        });
                map1.put("merattr",attrToJson);
            }
        }
        map.put("orderMerList",orderMerList);

    }
}
